<template>
  <!-- <div class="content-box">
  <common-header :title="title" ></common-header>-->
  <div class="page-content">
    <van-field
      v-model="oldPassword"
      type="password"
      label="原登陆密码"
      placeholder="请输入原登陆密码"
      clearable
      required
      :error-message="oldPasswordMessage"
    />
    <van-field
      v-model="newPassword"
      clearable
      type="password"
      label="新登陆密码"
      placeholder="请输入新登陆密码"
      required
      :error-message="newPasswordMessage"
    />
    <van-field
      v-model="surePassword"
      clearable
      type="password"
      label="确认密码"
      placeholder="请输入确认密码"
      required
      :error-message="surePasswordMessage"
    />
    <div class="btnPay" @click="finish()">完成修改</div>
    <div class="care">密码规则：长度6-18位 数字、英文、特殊符号且必须包含数字及英文</div>
    <commonFooter></commonFooter>
  </div>
  <!-- </div> -->
</template>
<script>
import { commonHeader, commonFooter } from "common";
import { passwordReg } from "@/utils/regRex";
import { resetPwdApi } from "@/api/user";
export default {
  name: "recharge",
  components: {
    commonHeader,
    commonFooter
  },
  methods: {
    finish() {
      let _this = this;
      this.oldPasswordMessage = "";
      this.newPasswordMessage = "";
      this.surePasswordMessage = "";
      if (!this.oldPassword) {
        this.oldPasswordMessage = "原密码不能为空";
      }
      if (!this.newPassword) {
        this.newPasswordMessage = "新密码不能为空";
      } else if (!passwordReg.test(this.newPassword)) {
        this.newPasswordMessage = "新密码格式格式不正确";
      }
      if (!this.surePassword) {
        this.surePasswordMessage = "确认密码不能为空";
      } else if (this.surePassword !== this.newPassword) {
        this.surePasswordMessage = "两次密码不一致";
      } else if (
        this.oldPassword &&
        this.newPassword &&
        passwordReg.test(this.newPassword)
      ) {
        resetPwdApi({
          old_password: this.oldPassword,
          password: this.newPassword
        }).then(res => {
          this.$toast({
            message: res.msg,
            duration: 500,
            onClose: function() {
              if (res.code == 200) _this.$router.go(-1);
            }
          });
        });
      }
    }
  },
  data() {
    return {
      title: "修改登陆密码",
      oldPassword: "",
      newPassword: "",
      surePassword: "",
      oldPasswordMessage: "",
      newPasswordMessage: "",
      surePasswordMessage: ""
    };
  }
};
</script>
<style lang="less" scoped>
@import "~styles/variable.less";
</style>